{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "\n",
    "# current_folder = os.path.dirname(os.path.abspath(__file__))\n",
    "# current_folder = os.path.dirname(os.path.realpath('__file__'))\n",
    "\n",
    "# folder_file_list =\n",
    "current_folder = os.getcwd()\n",
    "current_files = os.listdir(current_folder)\n",
    "\n",
    "for file in current_files:\n",
    "    part_list = file.split('.')\n",
    "    if not part_list[0].isdigit():\n",
    "        continue\n",
    "    num_list = list(part_list[0])\n",
    "\n",
    "    if len(num_list) == 4:\n",
    "        continue\n",
    "    while len(num_list) < 4:\n",
    "        num_list.insert(0, '0')\n",
    "    part_list[0] = \"\".join(num_list)\n",
    "    new_file = \".\".join(part_list)\n",
    "\n",
    "    # print(file)\n",
    "    # print(new_file)\n",
    "\n",
    "    # command = \"git mv \" + file + \" \" + new_file\n",
    "    command = \"mv \" + file + \" \" + new_file\n",
    "    print(command)\n",
    "    os.system(command)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "leetcode\n",
    "- 选择cn终端\n",
    "- cookie在all/的XHR里\n",
    "\n",
    "字符串\n",
    "\n",
    "+ \"string\"\\n\n",
    "+ \"\"string\"\""
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "gdb\n",
    "\n",
    "+ g++ -std=c++11 ./1382.将二叉搜索树变平衡.cpp -o test -g\n",
    "\n",
    "在windows中gdb无法打开含中文名称源文件\n",
    "\n",
    "win + 区域设置 -》 管理 -》更改系统区域设置 -》Beta版：使用UnicodeUTF-8提供全球语言支持\n",
    "\n",
    "CMakeList\n",
    "\n",
    "```\n",
    "SET(CMAKE_BUILD_TYPE \"Debug\")\n",
    "SET(CMAKE_CXX_FLAGS_DEBUG \"$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb\")\n",
    "SET(CMAKE_CXX_FLAGS_RELEASE \"$ENV{CXXFLAGS} -O3 -Wall\")\n",
    "```\n",
    "\n",
    "launch.json\n",
    "\n",
    "```\n",
    "\n",
    "{\n",
    "    \"version\": \"0.2.0\",\n",
    "    \"configurations\": [\n",
    "        \n",
    "        {\n",
    "            \"name\": \"(gdb) Launch\",\n",
    "            \"type\": \"cppdbg\",\n",
    "            \"request\": \"launch\",\n",
    "            \"program\": \"/home/quzheng/lc/test\",\n",
    "            \"args\": [],\n",
    "            \"stopAtEntry\": false,\n",
    "            \"cwd\": \"${workspaceFolder}\",\n",
    "            \"environment\": [],\n",
    "            \"externalConsole\": false,\n",
    "            \"MIMode\": \"gdb\",\n",
    "            \"setupCommands\": [\n",
    "                {\n",
    "                    \"description\": \"Enable pretty-printing for gdb\",\n",
    "                    \"text\": \"-enable-pretty-printing\",\n",
    "                    \"ignoreFailures\": true\n",
    "                }\n",
    "            ],\n",
    "            // \"preLaunchTask\": \"C/C++: g++ build active file\",\n",
    "            \"miDebuggerPath\": \"/usr/bin/gdb\"\n",
    "        }\n",
    "    ]\n",
    "    \n",
    "}\n",
    "\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "\n",
    "# command = \"git mv 0877.石子游戏.cpp 877.石子游戏.cpp\"\n",
    "command = \"mv 2.两数相加.cpp 0002.两数相加.cpp\"\n",
    "os.system(command)\n",
    "\n",
    "import subprocess\n",
    "\n",
    "\n",
    "# command = \"ipconfig -all\"\n",
    "completed_process_obj = subprocess.run(command, stdout=subprocess.PIPE)\n",
    "print(completed_process_obj.stdout.decode(\"gbk\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import subprocess\n",
    "\n",
    "\n",
    "command = \"ipconfig -all\"\n",
    "completed_process_obj = subprocess.run(command, stdout=subprocess.PIPE)\n",
    "print(completed_process_obj.stdout.decode(\"gbk\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "points = [[7,3],[19,19],[-16,3],[13,17],[-18,1],[-18,-17],[13,-3],[3,7],[-11,12],[7,19],[19,-12],[20,-18],[-16,-15],[-10,-15],[-16,-18],[-14,-1],[18,10],[-13,8],[7,-5],[-4,-9],[-11,2],[-9,-9],[-5,-16],[10,14],[-3,4],[1,-20],[2,16],[0,14],[-14,5],[15,-11],[3,11],[11,-10],[-1,-7],[16,7],[1,-11],[-8,-3],[1,-6],[19,7],[3,6],[-1,-2],[7,-3],[-6,-8],[7,1],[-15,12],[-17,9],[19,-9],[1,0],[9,-10],[6,20],[-12,-4],[-16,-17],[14,3],[0,-1],[-18,9],[-15,15],[-3,-15],[-5,20],[15,-14],[9,-17],[10,-14],[-7,-11],[14,9],[1,-1],[15,12],[-5,-1],[-17,-5],[15,-2],[-12,11],[19,-18],[8,7],[-5,-3],[-17,-1],[-18,13],[15,-3],[4,18],[-14,-15],[15,8],[-18,-12],[-15,19],[-9,16],[-9,14],[-12,-14],[-2,-20],[-3,-13],[10,-7],[-2,-10],[9,10],[-1,7],[-17,-6],[-15,20],[5,-17],[6,-6],[-11,-8]]\n",
    "\n",
    "ypoints = np.array(points)\n",
    "\n",
    "# plot\n",
    "plt.scatter(ypoints[:, 0], ypoints[:, 1], marker = 'o')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "\n",
    "def sort_the_folder(folder_path):\n",
    "    folder_file_list = os.listdir(folder_path)\n",
    "    new_file_list = []\n",
    "\n",
    "    for file in folder_file_list:\n",
    "        old_absolute_path = folder_path + os.sep + file\n",
    "\n",
    "        if os.path.isdir(old_absolute_path):\n",
    "            sort_the_folder(old_absolute_path)\n",
    "        else:\n",
    "            file_change_time = os.path.getmtime(old_absolute_path)\n",
    "            suffix = os.path.splitext(file)[1]\n",
    "\n",
    "            time_str = str(int(file_change_time))\n",
    "            while time_str in new_file_list:\n",
    "                time_str += '1'\n",
    "\n",
    "            new_absolute_path = folder_path + os.sep + time_str + suffix\n",
    "            os.rename(old_absolute_path, new_absolute_path)\n",
    "            new_file_list.append(time_str)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    # path = 'D:/Collections'\n",
    "    path = 'D:/Collections_version_5.0'\n",
    "    sort_the_folder(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "\n",
    "def unzip_the_folder(folder_path):\n",
    "    folder_file_list = os.listdir(folder_path)\n",
    "    zip_file_list = []\n",
    "    # print(folder_file_list)\n",
    "    for file in folder_file_list:\n",
    "        if file[-4 :] != \".zip\":\n",
    "            folder_file_list.remove(file)\n",
    "    # print(folder_file_list)\n",
    "    zip_file_list = folder_file_list\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    # path = 'D:/Collections'\n",
    "    path = 'D:/Collections_version_5.1'\n",
    "    unzip_the_folder(path)\n",
    "\n",
    "# no it turns out to be not valid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "\n",
    "# turn *.webp to *.jpg\n",
    "def transfer_the_folder(folder_path):\n",
    "    folder_file_list = os.listdir(folder_path)\n",
    "\n",
    "    for file in folder_file_list:\n",
    "        old_absolute_path = folder_path + os.sep + file\n",
    "\n",
    "        if os.path.isdir(old_absolute_path):\n",
    "            transfer_the_folder(old_absolute_path)\n",
    "        else:\n",
    "            # do it here\n",
    "            prefix_name = os.path.splitext(file)[0]\n",
    "            suffix = os.path.splitext(file)[1]\n",
    "\n",
    "            if suffix == \".webp\":\n",
    "                new_absolute_path = folder_path + os.sep + prefix_name + \".jpg\"\n",
    "                os.rename(old_absolute_path, new_absolute_path)\n",
    "\n",
    "            # print(old_absolute_path, new_absolute_path)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    # path = 'D:/Collections'\n",
    "    path = 'D:/collections_version_5.2/419290'\n",
    "    transfer_the_folder(path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "\n",
    "def concat_the_folder(folder_path):\n",
    "    folder_path = \"D:/collections_version_5.2/test\"\n",
    "    sub_folder_list = os.listdir(folder_path)\n",
    "\n",
    "    for sub_folder in sub_folder_list:\n",
    "        sub_folder_absolute_path = folder_path + \"/\" + sub_folder\n",
    "        print(sub_folder_absolute_path)\n",
    "\n",
    "        sub_file_list = os.listdir(sub_folder_absolute_path)\n",
    "        print(sub_file_list)\n",
    "\n",
    "        for file in sub_file_list:\n",
    "            old_absolute_path = sub_folder_absolute_path + \"/\" + file\n",
    "            new_absolute_path = sub_folder_absolute_path + \"/\" + sub_folder + file\n",
    "            os.rename(old_absolute_path, new_absolute_path)\n",
    "            # print(old_absolute_path, new_absolute_path)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    # path = 'D:/Collections'\n",
    "    path = \"\"\n",
    "    concat_the_folder(path)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.12 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "de518d29a315021d0ada4626802f04585d7f25474958fbfd96b5d319170ebe51"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
